import { fail, success } from '../common/ResResult'
import { Context } from 'koa'
import { get, post } from '../decorator/reqmethoddecorator'
import { Controller } from '../decorator/controllerdecorator'
import userinfoService from '../modules/userinfo/service/userinfoService'
// TS 装饰器 重构Koa 路由中的方法装饰器
@Controller('/usermodule')
class UserController {
  @post('/login')
  async login(ctx: Context) {
    const { username, psw } = ctx.request.body
    const userInfo = await userinfoService.login(username, psw)
    if (userInfo) {
      ctx.body = success(userInfo)
    } else {
      ctx.body = fail('用户名或者密码不正确，请检查后再重新登录')
    }
  }
}
